package com.vjmobi.test.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vjmobi.test.dao.UserMapper;
import com.vjmobi.test.entity.User;
import com.vjmobi.test.service.UserService;
import com.vjmobi.test.vo.page.PageReq;
import com.vjmobi.test.vo.page.PageResp;

@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private UserMapper userMapper;

	@Override
	public int add(User user) {
		return userMapper.add(user);
	}

	@Override
	public PageResp<User> findList(PageReq<User> page) {
		PageResp<User> resp = new PageResp<>();
		page.fillPageInfo(resp);
		// 查询数据总数
		long total = userMapper.total(page);
		resp.setTotal(total);
		// 如果数据大于0，才执行查询数据的操作；否则，没有数据，不需要去查询数据
		if (0 < total) {
			resp.setRecord(userMapper.findList(page));
		}
		return resp;
	}
}
